/**
 * 区域设置 编辑页
 *
 * 作者 admin
 * 日期 2024-07-31 14:35:47
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#incentiveRewardMatters-edit'),
        $location = $view.find('#location'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (incentiveRewardMatters) {
            form.val("incentiveRewardMatters-edit-form", {
                "rewardMattersId": incentiveRewardMatters.rewardMattersId,
                "tenantId": incentiveRewardMatters.tenantId,
                "mattersName": incentiveRewardMatters.mattersName,
                "rewardAmount": incentiveRewardMatters.rewardAmount,
                "rewardScore": incentiveRewardMatters.rewardScore,
                "sort": incentiveRewardMatters.sort,
            });
            if(incentiveRewardMatters.status === '1'){
                $view.find('input[type=checkbox]').attr("checked","true");
                form.render('checkbox');
            }
        } else {
            form.val("incentiveRewardMatters-edit-form", {
                "tenantId": POPUP_DATA.tenantId
            });
        }
    }

    form.on('submit(incentiveRewardMatters-edit-form-submit)', function (data) {
        if(data.field.status == "on"){
            data.field.status = '1';
        }else{
            data.field.status = '0';
        }
        console.log("保存信息"+JSON.stringify(data.field));
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm('保存提示', '是否保存奖励信息？', function () {
            if (data.rewardMattersId && data.rewardMattersId.length > 0) {
                febs.postArray(ctx + 'incentiveRewardMatters/update', data, function () {
                    layer.closeAll();
                    febs.alert.success('修改成功');
                    $('#febs-incentiveRewardMatters').find('#query').trigger('click');
                });
            } else {
                febs.postArray(ctx + 'incentiveRewardMatters', data, function () {
                    layer.closeAll();
                    febs.alert.success('新增成功');
                    $('#febs-incentiveRewardMatters').find('#query').trigger('click');
                });
            }
        });
    }

});